package com.cloud.pet.ops.controller.op;

import java.util.Objects;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.commons.Result;
import com.cloud.pet.api.manager.dc.PetDeviceManager;
import com.cloud.pet.api.manager.op.AlarmManager;
import com.cloud.pet.api.req.ds.PetDeviceOptReq;
import com.cloud.pet.api.req.op.AlarmReq;
import com.cloud.pet.api.req.op.AlarmStatReq;
import com.cloud.pet.api.resp.op.AlarmVo;

/**
 * 运维员工
 * 
 * @author lw
 * @date 2024/07/17
 */
@RestController
@RequestMapping("alarm")
public class AlarmController {
    @Resource
    private AlarmManager alarmManager;
    @Resource
    private PetDeviceManager petDeviceManager;

    /** 根据主键查询 **/
    @GetMapping(value = "/getAlarm/{id}")
    public Result<AlarmVo> getAlarm(@PathVariable("id") Integer id) {
        return alarmManager.getAlarm(id);
    }

    /** 首页告警各状态统计查询 **/
    @GetMapping(value = "/alarmStateCount/{empId}")
    public Result<?> alarmStateCount(@PathVariable("empId") Integer empId) {
        return alarmManager.alarmStateCount(empId);
    }
    // 首页预警列表
    /** 分页查询 运维人员的设备告警 **/
    @PostMapping(value = "/pageEmpAlarm")
    public Result<?> pageEmpAlarm(@RequestBody AlarmReq req) {
        return alarmManager.pageEmpAlarm(req);
    }
    
    /** 处理告警完成 **/
    @GetMapping(value = "/finish")
    public Result<?> finish(@RequestParam("id") Integer id, @RequestParam("empId") Integer empId) {
        return alarmManager.finish(id, empId);
    }
    
    
    
    
    

    /*** 按月告警统计分析 ***/
    @PostMapping(value = "/alarmStatMonth")
    public Result<?> alarmStatMonth(@RequestBody AlarmStatReq req) {
        return alarmManager.alarmStatMonth(req);
    }

    
    // 告警逾期计算更新
    @GetMapping(value = "/exceedTally")
    public Result<?> exceedTally(@RequestBody AlarmStatReq req) {
        return alarmManager.exceedTally(req);
    }

    /**
     * 设备信息上报, 测试告警生成
     * @return
     */
    @PostMapping(value = "/triggerAlarm")
    Result<?> triggerAlarm(@RequestBody PetDeviceOptReq petDeviceOptReq){
        if(Objects.isNull(petDeviceOptReq.getSn())){
            return Result.build(-1,"设备编码不存在，请重试") ;
        }

        return alarmManager.triggerAlarm(petDeviceOptReq) ;
    }
}
